import { defineComponent, ref, watch, openBlock, createElementBlock, normalizeClass, Fragment, renderList, unref, normalizeStyle, renderSlot, toDisplayString, createCommentVNode } from "vue";
import "./style/index.css";
const _hoisted_1 = ["onClick"];
const _hoisted_2 = { key: 0 };
const __default__ = defineComponent({ name: "ShrRadio" });
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    option: { default: () => [] },
    list: { default: void 0 },
    modelValue: { default: "" },
    color: { default: "#ffffff" },
    background: {},
    layout: { default: "horizontal" },
    prop: {},
    itemStyle: { default: {} },
    radioStyle: { default: () => ({ background: "rgba(64, 127, 249, 1)", color: "#ffffff" }) },
    maxTxt: { default: 9 }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit }) {
    var _a, _b;
    const props = __props;
    const label = ((_a = props.prop) == null ? void 0 : _a.label) || "label";
    const value = ((_b = props.prop) == null ? void 0 : _b.value) || "value";
    const activeKey = ref(props.modelValue);
    let preValue;
    const radioChoose = (item) => {
      const val = item[value];
      if (preValue !== val) {
        preValue = val;
        activeKey.value = val;
        emit("update:modelValue", val);
        emit("change", item);
      }
    };
    const getItemStyle = (item, style) => {
      return item.width ? {
        ...style,
        width: item.width
      } : style;
    };
    watch(() => props.modelValue, (val) => {
      activeKey.value = val;
      preValue = val;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(_ctx.layout === "horizontal" ? "radio-container" : "ver-radio-container")
      }, [
        (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.list || _ctx.option, (item, index) => {
          return openBlock(), createElementBlock("div", {
            key: index,
            class: normalizeClass(`radio-item ${activeKey.value === item[unref(value)] ? "active-radio-item" : ""}`),
            style: normalizeStyle(activeKey.value === item[unref(value)] ? getItemStyle(item, _ctx.radioStyle) : getItemStyle(item, _ctx.itemStyle)),
            onClick: ($event) => radioChoose(item)
          }, [
            renderSlot(_ctx.$slots, "tag", { data: item }),
            !_ctx.$slots.tag ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(item[unref(label)]), 1)) : createCommentVNode("", true)
          ], 14, _hoisted_1);
        }), 128))
      ], 2);
    };
  }
});
export {
  _sfc_main as default
};
